package com.ruoyi.weiriya.domain;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseIdEntity;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

/**
 * 用户停车记录对象 w_member_deposit_record
 * 
 * @author lynn
 * @date 2023-08-01
 */
@Data
@ApiModel(value = "WMemberDepositRecord", description = "用户停车记录对象")
public class WMemberDepositRecord extends BaseIdEntity
{
    private static final long serialVersionUID = 1L;

    /** id */
    @ApiModelProperty("id")
    private String id;

    /** 用户ID */
    @Excel(name = "用户ID")
    @ApiModelProperty("用户ID")
    private String memberId;

    @TableField(exist = false)
    @Excel(name = "用户昵称")
    @ApiModelProperty("用户昵称")
    private String memberName;

    /** 小区ID */
    @Excel(name = "小区ID")
    @ApiModelProperty("小区ID")
    private String areaId;

    @TableField(exist = false)
    @Excel(name = "小区名称")
    @ApiModelProperty("小区名称")
    private String areaName;

    /** 车辆ID */
    @Excel(name = "车辆ID")
    @ApiModelProperty("车辆ID")
    private String vehicleId;

    @ApiModelProperty("车辆类型（充电：w_vehicle_charge_type，门禁：w_vehicle_non_charge_type）")
    private String vehicleType;

    @TableField(exist = false)
    @Excel(name = "车辆类型名称")
    @ApiModelProperty("车辆类型名称")
    private String vehicleTypeName;

    /** 门禁ID（门禁唯一标识） */
    @Excel(name = "门禁ID")
    @ApiModelProperty("门禁ID（门禁唯一标识）")
    private String doorId;

    /** 开始时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("开始时间")
    private Date startTime;

    /** 结束时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("结束时间")
    private Date endTime;

    /** 总时长（分） */
    @Excel(name = "总时长（分）")
    @ApiModelProperty("总时长（分）")
    private Long totalDuration;

    /** 金额 */
    @Excel(name = "金额")
    @ApiModelProperty("金额")
    private Double amount;

    @ApiModelProperty("已扣金额")
    private Double withheldAmount;

    /** 状态（1计费中,2已结束,3非正常结束） */
    @Excel(name = "状态", readConverterExp = "1=计费中,2=已结束,3=非正常结束")
    @ApiModelProperty("状态（1计费中,2已结束,3非正常结束）")
    private Integer state;

    /** 会员类型（1月卡，2季卡，3年卡，4非会员） */
    @Excel(name = "会员类型", readConverterExp = "1=月卡,2=季卡,3=年卡,4=非会员")
    @ApiModelProperty("会员类型（1月卡，2季卡，3年卡，4非会员）")
    private Integer vipType;

    /** 创建者 */
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty("创建者")
    private String createBy;

    /** 创建时间 */
    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /** 更新者 */
    @TableField(fill = FieldFill.UPDATE)
    @ApiModelProperty("更新者")
    private String updateBy;

    /** 更新时间 */
    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;


    public <T> QueryWrapper<T> queryWrapper(){
        QueryWrapper<T> wrapper=new QueryWrapper<>();

        wrapper.like(StringUtils.isNotEmpty(id),"mdr.id" , id);
        wrapper.like(StringUtils.isNotEmpty(memberId),"mdr.member_id" , memberId);
        wrapper.like(StringUtils.isNotEmpty(areaId),"mdr.area_id" , areaId);
        wrapper.like(StringUtils.isNotEmpty(vehicleId),"mdr.vehicle_id" , vehicleId);
        wrapper.like(StringUtils.isNotEmpty(doorId),"mdr.door_id" , doorId);
        wrapper.eq(totalDuration != null,"mdr.total_duration" , totalDuration);
        wrapper.eq(vipType != null,"mdr.vip_type" , vipType);
        if(StringUtils.isNotNull(startTime)) {
            wrapper.ge("mdr.start_time", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, startTime) + " 00:00:01");
        }
        if(StringUtils.isNotNull(endTime)) {
            wrapper.le( "mdr.end_time", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, endTime) + " 23:59:59");
        }
        wrapper.orderByDesc("mdr.create_time");
        return wrapper;
    }

}
